syms s t
num_train = 512;
num_val = 256;
num_test = 256;
real_K = @(t, s) 2+cos(15.*pi.*(t-s));
img_K = @(t, s) sin(15.*pi.*(t-s));
real_u = @(t) sin(50.*pi.*t.^2);
img_u = @(t) cos(60.*pi.*t.^2+t);
x_lim = linspace(0, 1, num_train)';
x_lim2 = rand(num_test+num_val, 1);

real_f_dis = zeros(num_train+num_val+num_test, 1);
img_f_dis = zeros(num_train+num_val+num_test, 1);

for i = 1:num_train
    tt = x_lim(i);
    real_f_dis(i, 1) = integral(@(s)real_K(tt, s).*real_u(s), 0, tt) - integral(@(s)img_K(tt, s).*img_u(s), 0, tt);
    img_f_dis(i, 1) = integral(@(s)real_K(tt, s).*img_u(s), 0, tt) + integral(@(s)img_K(tt, s).*real_u(s), 0, tt);
end

for i = 1:num_val+num_test
    tt = x_lim2(i);
    real_f_dis(i+num_train, 1) = integral(@(s)real_K(tt, s).*real_u(s), 0, tt) - integral(@(s)img_K(tt, s).*img_u(s), 0, tt);
    img_f_dis(i+num_train, 1) = integral(@(s)real_K(tt, s).*img_u(s), 0, tt) + integral(@(s)img_K(tt, s).*real_u(s), 0, tt);
end

real_u_dis = real_u(x_lim);
img_u_dis = img_u(x_lim);

real_f_dis(1:num_train, 1) = -real_f_dis(1:num_train, 1) + real_u(x_lim);
img_f_dis(1:num_train, 1) = -img_f_dis(1:num_train, 1) + img_u(x_lim);
real_f_dis(num_train+1:end, 1) = -real_f_dis(num_train+1:end, 1) + real_u(x_lim2);
img_f_dis(num_train+1:end, 1) = -img_f_dis(num_train+1:end, 1) + img_u(x_lim2);
figure 
plot(x_lim, real_f_dis(1:num_train, 1))
hold on
plot(x_lim, img_f_dis(1:num_train, 1))
legend('real_f', 'img_f')
title('f')

figure 
plot(x_lim, real_u_dis)
hold on
plot(x_lim, img_u_dis)

legend('real_u', 'img_u')
title('u')

save('example_1.mat', "x_lim", "x_lim2", "real_u_dis", "img_u_dis", "img_f_dis", "real_f_dis", "num_train", "num_val", "num_test")

clear

